<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use common\components\Helper;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\business\models\BusinessContractSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '合同';
$this->params['breadcrumbs'][] = $this->title;
?>
<style media=print type="text/css">
    .noprint{visibility:hidden}
</style>

<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">
 


<div class="business-contract-index">


    <p>
        <?= Html::a('新建合同', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php
        echo GridView::widget([
            'dataProvider'=>$dataProvider,
            'filterModel'=>$searchModel,
            'showPageSummary'=>true,
            'pjax'=>true,
            'striped'=>true,
            'hover'=>true,
            'panel'=>['type'=>'primary', 'heading'=>'仔猪管理'],
            'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
            'headerRowOptions'=>['class'=>'kartik-sheet-style'],
            'filterRowOptions'=>['class'=>'kartik-sheet-style'],
            'columns'=>[
                [
                    'attribute'=>'displayorder',
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'attribute'=>'no',
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'attribute'=>'name',
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'label' => '种类',
                    'attribute'=>'cateid',
                    'width'=>'100px',
                    'value'=>'category.title',
                    'filterType'=>GridView::FILTER_SELECT2,
                    'filter'=>ArrayHelper::map(\common\models\business\BusinessContractCategory::find()->asArray()->all(),'id','title'),
                    'filterWidgetOptions'=>[
                        'pluginOptions'=>['allowClear'=>true],
                    ],
                    'filterInputOptions'=>['placeholder'=>'选择猪的种类'],
    //                    'group'=>true,  // enable grouping
                ],
                [
                    'attribute'=>'partyA',
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'attribute'=>'partyB',
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'attribute'=>'start_time',
                    'value' => function($model){
                        return date('Y-m-d',$model->start_time);

                    },
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'attribute'=>'end_time',
                    'value' => function($model){
                        return date('Y-m-d',$model->end_time);

                    },
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'attribute'=>'address',
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                    'width'=>'100px',
                ],
                [
                    'label' => '状态',
                    'format' => 'raw',
                    'attribute' => 'status',
                    'width'=>'170px',
                    'value' => function($model){
                        $setouttime = \common\models\sys\SysSetting::getValue('contract_out_time');
                        $outdate = $setouttime*3600*24+time();
                        if($model->end_time < time()){
                            return Html::label('已过期','',['class'=>'btn btn-info btn-xs']);
                        }else if($model->end_time < $outdate){
                            return Html::Label('剩余'.Helper::dateDifference(date('Y-m-d',$model->end_time),date('Y-m-d')).'天过期','',['class'=>'btn btn-danger btn-xs']);
                        }else{
//                          return '距离过期还有'.Helper::dateDifference(date('Y-m-d',$model->end_time),date('Y-m-d')).'天';
                            return Html::label('生效中','',['class'=>'btn btn-success btn-xs']);
                        }
                    },
                    'filterType'=>GridView::FILTER_SELECT2,
                    'filter'=>\common\models\business\BusinessContract::$statues,
                    'filterWidgetOptions'=>[
                        'pluginOptions'=>['allowClear'=>true],
                    ],
                    'filterInputOptions'=>['placeholder'=>'选择状态'],
                    'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                ],
                [
                    'class' => '\kartik\grid\ActionColumn',
                    'deleteOptions' => ['label' => '<i class="glyphicon glyphicon-remove"></i>'],

                ],

                [
                    'class' => '\kartik\grid\CheckboxColumn'
                ]
            ],
            'toolbar'=> [
                Yii::$app->request->get('id') !== null?[
                    'content' => Html::button('<i class="glyphicon glyphicon-plus"></i>', ['type'=>'button', 'title'=>'选中归为档案', 'class'=>'btn btn-success', 'id'=>'addpig'])
                ]:'',
                '{export}',
                '{toggleData}',
            ],
            'bordered'=>true,
            'condensed'=>true,
        ]);
    ?>

    <!--<div>
        <div>
            <input type="button" id="btnPrint" onclick="onprint()" value="print" />
        </div>
    </div>-->
   <!-- <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
        function printHtml(html) {
            var bodyHtml = document.body.innerHTML;
            document.body.innerHTML = html;
            window.print();
            document.body.innerHTML = bodyHtml;
        }
        function onprint() {
            $("a").attr('href','');
            $('.kv-align-middle').remove();
            var html = $("#w0-pjax").html();
            printHtml(html);
        }
    </script>-->
</div>
</div>
</div>
</section>
</section>





